<?php
namespace Chat\Model;
use Think\Model;

class MessageModel extends Model {
    
    protected $tableName = 'user_message';

    /**
     * @param    [type]     $from_uid [description]
     * @param    [type]     $to_uid   [description]
     * @param    [type]     $content  [description]
     * @param    [type]     $msg_type text 文字, image 图片
     */
    public function addMsg($from_uid, $to_uid, $content, $msg_type)
    {
        $data = [
            'msg_type'      => $msg_type,
            'from_uid'      => $from_uid,
            'to_uid'        => $to_uid,
            'content'       => $content,
            'is_read'       => 1,
            'status'        => 1,
            'create_time'   => time(),
        ];
        if($this->create($data)){
            if($id = $this->add()){
                return ['status'=>1, 'id'=>$id];
            }
        }
        return ['status'=>0];
    }
}